package algorithmTopics.matrix;

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(bf.readLine().trim());
        int[][] data = new int[N][N];
        int magicSum = N * (N * N + 1) / 2;
        // 幻方和

        // 读取输入
        for (int i = 0; i < N; i++) {
            StringTokenizer token = new StringTokenizer(bf.readLine());
            for (int j = 0; j < N; j++) {
                data[i][j] = Integer.parseInt(token.nextToken());
            }
        }
        bf.close();

        // 找出错误行和列
        List<Integer> errorRows = new ArrayList<>();
        List<Integer> errorCols = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            int rowSum = 0;
            int colSum = 0;
            for (int j = 0; j < N; j++) {
                rowSum += data[i][j];
                colSum += data[j][i];
            }
            if (rowSum != magicSum) {
                errorRows.add(i);
            }
            if (colSum != magicSum) {
                errorCols.add(i);
            }
        }

        int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
        // 交换错误位置的数字
        if (errorRows.size() == 2 && errorCols.size() == 2) {
            x1 = errorRows.get(0);
            y1 = errorCols.get(0);
            x2 = errorRows.get(1);
            y2 = errorCols.get(1);

            // 交换 (x1, y1) 和 (x2, y2)
            int temp = data[x1][y1];
            data[x1][y1] = data[x2][y2];
            data[x2][y2] = temp;

            // 输出交换的位置和原始值
            if (!verifyData(data, N, magicSum)) {
                x1 = errorRows.get(0);
                y1 = errorCols.get(1);
                x2 = errorRows.get(1);
                y2 = errorCols.get(0);
                temp = data[x1][y1];
                data[x1][y1] = data[x2][y2];
                data[x2][y2] = temp;
            }

            printData(x1, x2, y1, y2, data);
            System.exit(0);
            //被交换的那俩个刚好在某行某列满足条件，俩错误是在同一列或者同一行
        } else if (errorRows.size() == 0 && errorCols.size() == 2) {
            // 横坐标是一致的
            y1 = errorCols.get(0);
            y2 = errorCols.get(1);
            for (int i = 0; i < N; i++) {
                x1 = i;
                x2 = i;
                // 交换 (x1, y1) 和 (x2, y2)
                int[][] dataTemp = data;
                int temp = dataTemp[x1][y1];
                dataTemp[x1][y1] = dataTemp[x2][y2];
                dataTemp[x2][y2] = temp;
                if (verifyData(dataTemp, N, magicSum)) {
                    printData(x1, x2, y1, y2, dataTemp);
                    System.exit(0);
                }
            }
        } else if (errorRows.size() == 2 && errorCols.size() == 0) {
            // 横坐标是一致的
            x1 = errorRows.get(0);
            x2 = errorRows.get(1);
            for (int i = 0; i < N; i++) {
                y1 = i;
                y2 = i;
                // 交换 (x1, y1) 和 (x2, y2)
                int[][] dataTemp = data;
                int temp = dataTemp[x1][y1];
                dataTemp[x1][y1] = dataTemp[x2][y2];
                dataTemp[x2][y2] = temp;
                if (verifyData(dataTemp, N, magicSum)) {
                    printData(x1, x2, y1, y2, dataTemp);
                    System.exit(0);
                }
            }
        }



    }

    private static void printData(int x1, int x2, int y1, int y2, int[][] data) {
        System.out.println((x1 + 1) + " " + (y1 + 1) + " " + data[x1][y1]);
        System.out.println((x2 + 1) + " " + (y2 + 1) + " " + data[x2][y2]);
    }

    private static boolean verifyData(int[][] data, int N, int magicSum) {
        for (int i = 0; i < N; i++) {
            int rowSum = 0;
            int colSum = 0;
            for (int j = 0; j < N; j++) {
                rowSum += data[i][j];
                colSum += data[j][i];
            }
            if (rowSum != magicSum || colSum != magicSum) {
                return false;
            }
        }
        return true;
    }
}